#pragma link "cspin"
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Globals.h"


#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::RedBarChange(TObject *Sender)
{
  char buf[20];
  //
  if ( iCanDraw )
  {
    map.Color  = RedBar->Position << 11;
    map.Color |= GreenBar->Position <<  5;
    map.Color |= BlueBar->Position <<  0;
    //
    sprintf(buf,"Color: $%04X", map.Color );
    Form2->Caption = AnsiString( buf );
    
    memsetw( ScrBuf, 0x738E, 320 * 240 );
    MenuMap( ScrBuf, &map , 320);
    Form1->FormPaint( NULL );
  }
}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::CurStatusClick(TObject *Sender)
{
  if ( CurStatus->Checked ){
    map.Cursor = 1;
    CurStatus->Caption = "Cursor On";
    MaxY->Enabled = true;
    MaxX->Enabled = true;
    MovY->Enabled = true;
    MovX->Enabled = true;
  } else {
    MaxY->Enabled = false;
    MaxX->Enabled = false;
    MovY->Enabled = false;
    MovX->Enabled = false;
    map.Cursor = 0;
    CurStatus->Caption = "Cursor Off";
  }

  memsetw( ScrBuf, 0x738E, 320 * 240 );
  MenuMap( ScrBuf, &map, 320 );
  Form1->FormPaint( NULL );

}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::MaxYKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
  //
  TCSpinEdit *Temp = (TCSpinEdit *)Sender;

  switch( Key )
  {
     case VK_NEXT : Temp->Value += 5; break; // page down
     case VK_PRIOR: Temp->Value -= 5; break; // page up
     case VK_UP   : Temp->Value -= 1; break;
     case VK_DOWN : Temp->Value += 1; break;
     default : Key = 0; return;
  }

  map.Maxy = MaxY->Value;
  map.Maxx = MaxX->Value;
  map.Movy = MovY->Value;
  map.Movx = MovX->Value;
}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::MaxYKeyPress(TObject *Sender, char &Key)
{
  Key = 0;
}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::CurListChange(TObject *Sender)
{
  map.Index = CurList->ItemIndex + CURSORBASE;
  memsetw( ScrBuf, 0x738E, 320 * 240 );
  MenuMap( ScrBuf, &map, 320 );
  Form1->FormPaint( NULL );
}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::FormCreate(TObject *Sender)
{
  CurList->ItemIndex = 0;
}


/////////////////////////////////
//                             //
/////////////////////////////////
void __fastcall TForm2::MaxYChange(TObject *Sender)
{
  map.Maxy = MaxY->Value;
  map.Maxx = MaxX->Value;
  map.Movy = MovY->Value;
  map.Movx = MovX->Value;

  memsetw( ScrBuf, 0x738E, 320 * 240 );
  MenuMap( ScrBuf, &map, 320 );
  Form1->FormPaint( NULL );
}


